/**
 * 
 */
package com.google.codemirror2_gwt.client.util;

import com.google.codemirror2_gwt.client.CodeMirrorWrapper;
import com.google.codemirror2_gwt.client.ExtraKeyEventHandler;

/**
 * @author Federico De Faveri defaveri@gmail.com
 *
 */
public class SimpleHint implements ExtraKeyEventHandler {
	
	protected HintsProvider hintsProvider;
	
	/**
	 * @param hintsProvider
	 */
	public SimpleHint(HintsProvider hintsProvider) {
		this.hintsProvider = hintsProvider;
	}

	/**
	 * @return the hintsProvider
	 */
	public HintsProvider getHintsProvider() {
		return hintsProvider;
	}

	/**
	 * @param hintsProvider the hintsProvider to set
	 */
	public void setHintsProvider(HintsProvider hintsProvider) {
		this.hintsProvider = hintsProvider;
	}

	@Override
	public void onExtraKeyEvent(CodeMirrorWrapper mirrorWrapper) {
		showHints(mirrorWrapper, hintsProvider);		
	}
	
	protected native void showHints(CodeMirrorWrapper mirrorWrapper, HintsProvider hintsProvider)/*-{
    	$wnd.CodeMirror.simpleHint(mirrorWrapper, 
    		function(){	
    			return hintsProvider.@com.google.codemirror2_gwt.client.util.HintsProvider::getHints(Lcom/google/codemirror2_gwt/client/CodeMirrorWrapper;)(mirrorWrapper);
   			}
    	);
  	}-*/;
}
